package com.liveneo.adapter.mobile.model.dto;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.liveneo.adapter.base.entity.PrpmLossAccessory;
import com.liveneo.adapter.base.entity.PrpmLossFit;
import com.liveneo.adapter.base.entity.PrpmLossMain;
import com.liveneo.adapter.base.entity.PrpmLossRepair;

public class PlatTurnsMobileDto {
    public static LossSingleDto turnsLossSingleDto(PlatLossSingleDto platLossSingleDto) throws Exception {
        LossSingleDto lossSingleDto = new LossSingleDto();
        // 定损单主信息
        PrpmLossMain prpmLossMain = platLossSingleDto.getLossMain();
        MobileLossMainDto mobileLossMainDto = new MobileLossMainDto();
        if (prpmLossMain != null && !"".equals(prpmLossMain)) {
            if (prpmLossMain.getLossId() != null && !"".equals(prpmLossMain.getLossId())) {
                BeanUtils.copyProperties(mobileLossMainDto, prpmLossMain);
            }
        }
        // 定损单辅料信息
        List<PrpmLossAccessory> lossAccessoryList = platLossSingleDto.getLossAccessoryList();
        List<MobileLossAccessoryDto> mobileLossAccessoryList = new ArrayList<MobileLossAccessoryDto>();
        if (lossAccessoryList != null && lossAccessoryList.size() > 0) {
            for (int i = 0; i < lossAccessoryList.size(); i++) {
                MobileLossAccessoryDto mobileLossAccessoryDto = new MobileLossAccessoryDto();
                BeanUtils.copyProperties(mobileLossAccessoryDto, lossAccessoryList.get(i));
                mobileLossAccessoryList.add(mobileLossAccessoryDto);
            }
        }
        // 定损单换件信息
        List<PrpmLossFit> lossFitList = platLossSingleDto.getLossFitList();
        List<MobileLossFitDto> mobileLossFitList = new ArrayList<MobileLossFitDto>();
        if (lossFitList != null && lossFitList.size() > 0) {
            for (int i = 0; i < lossFitList.size(); i++) {
                MobileLossFitDto mobileLossFitDto = new MobileLossFitDto();
                BeanUtils.copyProperties(mobileLossFitDto, lossFitList.get(i));
                mobileLossFitList.add(mobileLossFitDto);
            }
        }
        // 定损单修理件信息
        List<PrpmLossRepair> lossRepairList = platLossSingleDto.getLossRepair();
        List<MobileLossRepairDto> mobileLossRepairList = new ArrayList<MobileLossRepairDto>();
        if (lossRepairList != null && lossRepairList.size() > 0) {
            for (int i = 0; i < lossRepairList.size(); i++) {
                MobileLossRepairDto mobileLossRepairDto = new MobileLossRepairDto();
                BeanUtils.copyProperties(mobileLossRepairDto, lossRepairList.get(i));
                mobileLossRepairList.add(mobileLossRepairDto);
            }
        }
        lossSingleDto.setPrpmLossMain(mobileLossMainDto);
        lossSingleDto.setLossAccessoryList(mobileLossAccessoryList);
        lossSingleDto.setPrpmLossFitList(mobileLossFitList);
        lossSingleDto.setPrpmLossRepair(mobileLossRepairList);
        return lossSingleDto;
    }
}
